﻿<template>
    <my-dialog v-model="dlgVisible" :title="title" :width="width" @opened="onDlgOpened">
        <div style="min-height:340px; margin: -10px;" v-loading="loading">
            <my-grid :tbname="tbname" v-if="hideListHeader" ref="grid" v-model:search="search" :fields="fields"></my-grid>
            <my-list-page v-else :tbname="tbname" :defaultSearch="defaultSearch" v-bind="listAttrs"></my-list-page>
        </div>
        <template #footer>

            <!--自定义功能按钮-->
            <template v-for="btn in actions2" :key="btn.label">
                <el-button :type="btn.type" v-if="btn.label && checkIf(btn.vif)" @click="doClick(btn.click)">{{
                        btn.label
                }}</el-button>
            </template>

            <el-button @click="close()" type="default">取消</el-button>
        </template>
    </my-dialog>
</template>

<script>
import { Utils } from "./main";
import MyListPage from './MyListPage.vue';
import MyMListPageVue from "./MyMListPage.vue";

export default {
    components: { MyListPage,MyMListPageVue },
    name: "MyListDlg",
    props: {
        tbname: {
            type: String,
            required: true,
        },
        title:String,
        width:[String,Number],
        actions:Array,
        fields:String,
        hideListHeader:Boolean,
        defaultSearch:Object,
        listAttrs:Object,
    },
    data() {
        return {
            dlgVisible:false,
            search:null,
            loading:false,
        };
    },
    methods: {
        onDlgOpened(){
            if(this.$refs.grid){
                this.loading = true;
                this.$refs.grid.loadData(1).finally(()=>{
                    this.loading = false;
                });
            }
        },
        checkIf(vif) {
            if (typeof vif == "function") {
                return vif.apply(this);
            } else if (typeof vif == "string") {
                return this.computeData[vif] != false;
            }
            return true;
        },
        doClick(func) {
            Utils.doFunc(func, this);
        },

        open() {
            this.dlgVisible = true;
            this.search = {...this.defaultSearch};
        },

        
        close() {
            this.dlgVisible = false;
        },
        

    },
    computed:{
        actions2(){

        }
    }
   
};
</script>

<style scoped>
.el-button {
    padding: 4px 8px;
}

.el-button+.el-button {
    margin-left: 6px;
}

</style>